package hrms.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import hrms.entity.Reward;
import hrms.service.RewardServiceImpl;
import hrms.util.LogUtil;
import hrms.util.Result;

@Controller
@RequestMapping("/reward")
public class RewardController {
	
	@Resource(name="rewardService")
	private RewardServiceImpl rewardService;
	
	@ExceptionHandler
	public String exHandle(Exception ex, HttpServletRequest req) {
		LogUtil.saveEx(ex);
		return "error";
	}
	
	@ResponseBody
	@RequestMapping("/loadReward.sls")
	public Result<List<Reward>> executeA(HttpServletRequest req ,HttpServletResponse res){
		String page = req.getParameter("page");
		Result<List<Reward>> result = rewardService.findByPage(page,res);
		return result;
	}
	
	@ResponseBody
	@RequestMapping("/rewardPage.sls")
	public Result<Map<String,Integer>> executeB2(HttpServletRequest req){
		Result<Map<String,Integer>> result = rewardService.pageTotal(req);
		return result;
	}
	
	
	@ResponseBody
	@RequestMapping("/addReward.sls")
	public Result<Object> executeB3(HttpServletRequest req){
		String type = req.getParameter("type");
		String name = req.getParameter("name");
		String detail = req.getParameter("detail");
		String deal= req.getParameter("deal");
		String date = req.getParameter("date");
		System.out.println("1");
		return rewardService.addReward( type,  name, detail, deal,date);
	}
	
	/*
	@ResponseBody
	@RequestMapping("/updatereward.sls")
	public Result<Object> executeB4(HttpServletRequest req){
		String rewardId = req.getParameter("rewardId");
		String rewardName = req.getParameter("rewardName");
		String rewardAge = req.getParameter("rewardAge");
		String rewardSex = req.getParameter("rewardSex");
		String rewardJob = req.getParameter("rewardJob");
		String rewardDept = req.getParameter("rewardDept");
		return rewardService.uppdatereward(rewardId, rewardName,  rewardSex, rewardAge, rewardJob, rewardDept,req);
	}
	@ResponseBody
	@RequestMapping("/changeState.sls")
	public Result<Object> executeI(HttpServletRequest req){
		String rewardId = req.getParameter("id");
		return rewardService.changeState(rewardId, req);
	}
	
	@ResponseBody
	@RequestMapping("/showreward.sls")
	public Result<reward> executeII(HttpServletRequest req){
		String rewardId = req.getParameter("rewardId");
		return rewardService.findreward(rewardId, req);
	}
	*/
	@ResponseBody
	@RequestMapping("/searchReward.sls")
	public Result<List<Reward>> executeAA(HttpServletRequest req ,HttpServletResponse res){
		String name = req.getParameter("name");
		if(name == null || name == ""){
			return rewardService.findByPage("1",res);
		}
		return rewardService.search(name);
	}
}